package com.ruoyi.liborder.controller;


import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.liborder.domain.LibOrderRecord;
import com.ruoyi.liborder.service.ILibOrderRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/lib/order")
public class LibController extends BaseController {
    @Autowired
    private ILibOrderRecordService libOrderRecordService;

    /**
     * 查询预约列表
     */
    @PreAuthorize("@ss.hasPermi('lib:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(LibOrderRecord libOrderRecord) {
        startPage();
        List<LibOrderRecord> list = libOrderRecordService.selectLibOrderRecordList(libOrderRecord);
        return getDataTable(list);
    }

    /**
     * 导出预约列表
     */
    @PreAuthorize("@ss.hasPermi('lib:order:export')")
    @Log(title = "预约", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LibOrderRecord libOrderRecord) {
        List<LibOrderRecord> list = libOrderRecordService.selectLibOrderRecordList(libOrderRecord);
        ExcelUtil<LibOrderRecord> util = new ExcelUtil<>(LibOrderRecord.class);
        util.exportExcel(response, list, "预约数据");
    }

    /**
     * 获取预约详细信息
     */
    @PreAuthorize("@ss.hasPermi('lib:order:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") String recordId) {
        return AjaxResult.success(libOrderRecordService.selectLibOrderRecordByRecordId(recordId));
    }

    /**
     * 新增预约
     */
    @PreAuthorize("@ss.hasPermi('lib:order:add')")
    @Log(title = "预约", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LibOrderRecord libOrderRecord) {
        return toAjax(libOrderRecordService.insertLibOrderRecord(libOrderRecord));
    }

    /**
     * 修改预约
     */
    @PreAuthorize("@ss.hasPermi('lib:order:edit')")
    @Log(title = "预约", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LibOrderRecord libOrderRecord) {
        return toAjax(libOrderRecordService.updateLibOrderRecord(libOrderRecord));
    }

    /**
     * 删除预约
     */
    @PreAuthorize("@ss.hasPermi('lib:order:remove')")
    @Log(title = "预约", businessType = BusinessType.DELETE)
    @DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable String[] recordIds) {
        return toAjax(libOrderRecordService.deleteLibOrderRecordByRecordIds(recordIds));
    }
}
